//
// Created by admin on 2024-5-20
// 高精度计算--subtract
// OJ:https://www.luogu.com.cn/problem/P2142 pass
// OJ:http://ybt.ssoier.cn:8088/problem_show.php?pid=1169 pass
//


/*
 * 99-99=0
 * 22-11=11
 * 111-12=99
 * 166-32=134
 * 11-122=-111
 * 111-122=-11
 * 30141-8160=21981
 * 12-14=-2
 */
#include <iostream>

using namespace std;

bool compare(string x, string y)
{
    if(x.size()>y.size())
        return true;
    if(x.size()<y.size())
        return false;
    for (int i = 0; i < x.size(); ++i)
    {
        if (x[i]>y[i])
            return true;
        if (x[i]<y[i])
            return false;
    }
    return true;
}

string subtract(string x, string y)
{
    string ret;
    bool negtive=false;
    if (x==y)
        return "0";
    // 保证x>y
    if(!compare(x,y))
    {
        swap(x,y);
        negtive=true;
    }
    // 保证一样长
    while(x.size()>y.size())
        y="0"+y;
    int l[x.size()]={0};
    for (int i = 0; i < x.size(); ++i)
    {
        l[i]=x[i]-y[i];
//        cout<<l[i]<<' ';
    }
    // 处理借位
    for (int i = x.size()-1; i >=0 ; --i)
    {
        if (l[i]<0)
        {
            l[i]+=10;
            --l[i-1];
        }
        ret=to_string(l[i])+ret;
    }
    // 处理前边多余的零
    bool zero=ret[0]=='0';
    string ans;
    for (int i = 0; i < x.size(); ++i)
    {
        if (ret[i]=='0' && zero)
            continue;
        else if (ret[i]!='0')
            zero=false;
        ans=ans+ret[i];
    }
    if (negtive)
        ans='-'+ans;
    return ans;
}

int main()
{
    // a-b
    string a = "112", b = "100"; // 12
    a = "212", b = "103"; // 109
    a = "99", b = "99"; //0
    a = "11", b = "122";  // -111
    a = "111", b = "122"; // -11
    a = "30141", b = "8160"; //21981
//    a = "8160", b = "30141"; //-21981
//    a="12",b="14";  // -2
//    cin>>a>>b;
//    cout<<compare(a,b)<<endl;
    cout<<subtract(a,b);
    return 0;
}